-- lock_ring
-- created by panyl
-- 进入下一层触发一些处理（紧箍的效果）

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,
    -- 触发
    trigger = function(who, prop, targetPos)
        -- 不是玩家
        if who.type ~= OBJECT_TYPE_USER then
            return false;
        end

        local slimeSkill = tonumber(prop[2]);
        local p = PropM.combine(who, "gain_slime_skill", slimeSkill);
        local level = p[3];
        if level <= 0 then
            -- 没有“大闹天宫”
            return false;
        end

        local painful = 0;
        local bleeding = 5;  -- 5%流血
        local bonusList = {};

        if level >= 5 then
            -- 疼痛值+5
            painful = painful + 5;
        end
        if level >= 4 then
            -- 提升属性,50%概率5点血蓝，25%概率10点血蓝， 25%概率1点攻魔
            local arr = { { 2, "max_hp", 10, }, { 2, "max_mp", 10, },
                          { 2, "max_hp", 5, },  { 2, "max_mp", 5,  },
                          { 2, "max_hp", 5, },  { 2, "max_mp", 5,  },
            { 2, "attack", 1,  }, { 2, "magic",  1,  }, };

            local rand = DungeonM.getRandSeed("lock_ring") % #arr + 1;
            table.insert(bonusList, arr[rand]);
        end
        if level >= 3 then
            -- 疼痛值+10
            painful = painful + 5;
        end
        if level >= 2 then
            -- 流血-2%
            bleeding = bleeding - 2;
        end
        painful = painful + 5;

        -- 收集奖励
        BonusM.startBonusCollect();

        for _, bonus in pairs(bonusList) do
            BonusM.doBonus(bonus, "lock_ring");
        end

        BonusM.endBonusCollect();

        -- 斯巴达专属加成
        local battleCry = PropM.combine(who, "battle_cry", 1);
        painful = PropM.apply(battleCry, painful);

        -- 疼痛值
        DungeonServiceM.addDungeonAttrib("painful", painful);

        -- 流血
        local damage = math.modf(who:queryAttrib("max_hp") * bleeding / 100);

        -- 延迟播放受创
        ME.user.dbase:setTemp("delayHpEffect", damage);

        CombatM.doDamage(who, who, damage, 0);
        EventMgr.fire(event.PLAYER_MOVE);

        return true;
    end,

    desc = function(prop)
        local slimeSkill = tonumber(prop[2]);
        local p = PropM.combine(ME.user, "gain_slime_skill", slimeSkill);
        local level = 5;

        local desc = getLocStr("lock_ring_base_desc");

        for lv = 1, level do
            desc = desc .. getLocStr("lock_ring_lv" .. lv);
        end

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end,
};
